<?php
class FL_Core {
	const ERR_WRONG_CONFIGURATION 	= 100;
	const ERR_INVALID_INPUT			= 200;
	
	const CONFVAR_DB_TYPE     		= 'DB_TYPE';
	const CONFVAR_DB_HOST     		= 'DB_HOST';
	const CONFVAR_DB_USER     		= 'DB_USER';
	const CONFVAR_DB_PASS     		= 'DB_PASSWORD';
	const CONFVAR_DB_DFLT_SCH 		= 'DB_DEFAULT_SCHEME';
	const CONFVAR_DB_TABLES_PREFIX 	= 'DB_TABLES_PREFIX';
	const CONFVAR_CMS_PAGE_LEN		= 'CMS_PAGE_LEN';
	const CONFVAR_CMS_ZERO_PAGE     = 'CMS_ZERO_PAGE';

	const TN_SEP = '_'; // table name parts separator
	
	// framework configuration
	protected static $a_config = array(
		self::CONFVAR_DB_TYPE			=> 'MySQL',
		self::CONFVAR_DB_HOST			=> 'localhost',
		self::CONFVAR_DB_USER			=> 'root',
		self::CONFVAR_DB_PASS			=> '1111',
		self::CONFVAR_DB_DFLT_SCH		=> 'test',
		self::CONFVAR_DB_TABLES_PREFIX	=> 'FL',
		self::CONFVAR_CMS_PAGE_LEN		=> 20,
		self::CONFVAR_CMS_ZERO_PAGE		=> false
	);
	
	/**
	 * 
	 * instance of DBA
	 * @var FL_DBA
	 */
	protected static $_o_dba = null;
	
	public static function setConfigVar($name, $value){
		self::$a_config[$name] = $value;
	}	
	
	public static function getException($code, $message){		
		return new FL_Exception($message, $code);
	}
	
	public static function setDbaInstance(){
		$dba_class_name = 'FL_DBA_' . self::$a_config[self::CONFVAR_DB_TYPE];
		if(class_exists($dba_class_name))
			self::$_o_dba = call_user_func($dba_class_name . '::getInstance');
		else
			throw self::getException(self::ERR_WRONG_CONFIGURATION, 'class ' . $dba_class_name . ' not found!');			
	}
	
	
}

class FL_Exception extends Exception {}